﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jacaranda.Model
{
    public static class ExtensionsForListOfEntity
    {
        //public static void Save(this List<Entity> entities)
        //{
        //    EntityMetadataCache.Instance.GetAssociationFields(GetType()).ToList().ForEach(i => i.Delete(this));

        //    foreach (AssociationField field in EntityMetadataCache.Instance.GetAssociationFields(GetType()))
        //    {
        //        foreach (Entity target in field.GetAssociationsFromField(this))
        //        {
        //            field.Insert(this, target);
        //        }
        //    }


        //    DataTable existing = DataPortal.Select(string.Format("SELECT * FROM {0} WHERE {1}='{2}'", GetTableName(GetType()), PrimaryKey.FieldName, GetValueOfPrimaryKey()));

        //    if (existing.Rows.Count == 0)
        //    {
        //        existing.Rows.Add(existing.NewRow());
        //    }

        //    Mapper.SingleEntityToRelation(existing.Rows[0], this);
        //    DataPortal.Update(GetTableName(GetType()), existing);
        //}
    }
}
